package org.jumiz.javafx.client.util;

import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.stage.Screen;
import javafx.stage.Stage;
import org.jumiz.javafx.client.pages.commonents.IPaneCloneable;
import org.jumiz.javafx.client.pages.commonents.JumizScene;
import org.jumiz.javafx.client.pages.commonents.LayoutPane;

/**
 * 场景切换
 */
public class SwitchScene {

    static Screen screen = Screen.getPrimary();

    private static Stage primaryStage;

//    public static Object currentPane;

//    public static volatile int delayTime = -1;

//    public static Thread thread = new Thread(new Runnable() {
//        @Override
//        public void run() {
//            while (true) {
//                if (delayTime > 0) {
//                    delayTime--;
//                } else if (delayTime == 0) {
//                    SwitchScene.switchScene((Pane) currentPane);
//                    delayTime--;
//                }
//                try {
//                    Thread.sleep(1L);
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            }
//        }
//    });

    public static void registerStage(Stage primaryStage) {
        SwitchScene.primaryStage = primaryStage;
//        thread.start();
    }

//    public static void delaySwitchScene(Pane pane) {
//        SwitchScene.delayTime = 100;
//        SwitchScene.currentPane = pane;
//    }

    public static void switchScene(Scene scene) {
        SwitchScene.primaryStage.setScene(scene);
    }

//    public static double currentHeight() {
//        return SwitchScene.primaryStage == null ? defaultHeight() : SwitchScene.primaryStage.getHeight();
//    }
//
//    public static double currentWidth() {
//        return SwitchScene.primaryStage == null ? defaultWidth() : SwitchScene.primaryStage.getWidth();
//    }

    public static double defaultWidth() {
        return screen.getBounds().getWidth() * 0.9;
    }

    public static double defaultHeight() {
        return screen.getBounds().getHeight() * 0.9;
    }

    public static void switchScene(Pane pane) {
        SwitchScene.switchScene(new JumizScene(pane, defaultWidth(), defaultHeight()));
    }
}
